package mrusanov.experience

object LevelSystem {
  private val maxLevel = 1000
  private var levels:Vector[Int] = Vector()
  for (i <- 1.until(maxLevel)) {
      levels = levels :+ expPoints(i)
  }

  def level(exp:Int) : Int = {
    require(exp >= 0, "Expirience cann't be less than zero")

    // TODO add binary search
    for ((v, k) <- levels.view.zipWithIndex) {
      if (v > exp) {
        return k
      }
    }

    // level cap
    levels.size
  }

  private def expPoints(level:Int) = 10 * (level - 1) * level
}
